<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 2.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/**
 * Installer - Step 4 - Insert Templates
 */
class install_step_4
{
  var $refresh_after_step = true;
  var $await_input        = false;
  
  function install_step_4( &$installer )
  {
    $this->installer =& $installer;
    $this->ipsclass =& $installer->ipsclass;
  }
  
  function run_step()
  {
    $this->installer->xml->xml_parse_document( file_get_contents( './data-install/ineo_templates.xml' ) );
    $template_array_tmp = $this->installer->xml->xml_array;

    foreach ( $template_array_tmp['templateexport']['templategroup']['template'] as $key => $value )
    {
      $this->ipsclass->DB->simple_construct( array( 'select' => 'suid', 'from' => 'skin_templates',
                                                    'where' => 'group_name = \''.$value['group_name']['VALUE'].
                                                    '\' AND func_name = \''.$value['func_name']['VALUE'].'\' AND set_id = 1' ) );
      $this->ipsclass->DB->simple_exec();
      $data = $this->ipsclass->DB->fetch_row();

      if ( $data['suid'] )
      {
        $this->ipsclass->DB->do_update( 'skin_templates', array( 'func_data' => $value['func_data']['VALUE'],
                                        'section_content' => $value['section_content']['VALUE'],
                                        'updated' => time() ),
                                        'suid = '.$data['suid'] );
      }
      else
      {
        $this->ipsclass->DB->do_insert( 'skin_templates', array( 'func_data' => $value['func_data']['VALUE'],
                                        'func_name' => $value['func_name']['VALUE'],
                                        'section_content' => $value['section_content']['VALUE'],
                                        'group_name' => $value['group_name']['VALUE'],
                                        'updated' => time(),
                                        'set_id' => 1 ) );
      }
    }
    
    $this->installer->status_text .= 'Template bits added to the database.<br />';
  }
}

?>